import base64
import json
import pickle


class CookieSecret(object):
    # 加密
    @classmethod
    def dumps(cls,data):
        data_bytes=pickle.dumps(data)
        base64_bytes=base64.b64encode(data_bytes)
        return base64_bytes.decode()


    # 解密
    @classmethod
    def loads(cls,data):
        base64_decode=base64.b64decode(data)
        pickle_result=pickle.loads(base64_decode)
        return pickle_result


#
# if __name__ == '__main__':
#
#     # json str<-->dict(list)
#     data_dict = {
#         1:"a",
#         'name':'zhangsan'
#     }
#
#     json_str = json.dumps(data_dict)
#     json_dict = json.loads(json_str)
#
#
#
#     # pickle  Python数据类型<-->bytes
#     pickle_bytes = pickle.dumps(data_dict)
#     pickle_dict = pickle.loads(pickle_bytes)
#
#     print("pickle_bytes",pickle_bytes)
#     print("pickle_dict",pickle_dict)
#
#     # base64 编解码
#     base64_bytes = base64.b64encode(pickle_bytes)
#     base64_decode = base64.b64decode(base64_bytes)
#     print("base64_bytes",base64_bytes)
#     print("base64_decode",base64_decode)
#
#     result = pickle.loads(base64_decode)
#     print("result",result)
